package com.edusite

class LogbookController {

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

    def index = {
        redirect(action: "list", params: params)
    }

    def list = {
        if (!session.user)
           redirect (uri:"/")
           else if (session.user.tipo != "admin")
              redirect (uri:"/alumnos/indice")
              
        params.max = Math.min(params.max ? params.int('max') : 10, 100)
        params.order="desc"
        params.sort="salida"
        [logbookInstanceList: Logbook.list(params), logbookInstanceTotal: Logbook.count()]
    }
        def conectados = {
        params.max = Math.min(params.max ? params.int('max') : 10, 100)
        [logbookInstanceList: Logbook.list(params), logbookInstanceTotal: Logbook.count()]
    }


    def create = {
        def logbookInstance = new Logbook()
        logbookInstance.properties = params
        return [logbookInstance: logbookInstance]
    }

    def save = {
        def logbookInstance = new Logbook(params)
        if (logbookInstance.save(flush: true)) {
            flash.message = "${message(code: 'default.created.message', args: [message(code: 'logbook.label', default: 'Logbook'), logbookInstance.id])}"
            redirect(action: "show", id: logbookInstance.id)
        }
        else {
            render(view: "create", model: [logbookInstance: logbookInstance])
        }
    }

}
